wifi.setmode(wifi.STATION)
wifi.sta.config({ ssid = "admin123", pwd = "12345678" })
wifi.sta.connect()

function boa_rules()
    http.get("http://10.35.155.30/cgi-bin/rules", nil, function (status_code, body)
        if code == -1  then
            print("get fail!")
        else
            print("status_code : ".. status_code,  "body: "..body)
            data = sjson.decode(body)
            print("code: "..data.code)
            if data.code == 0 then
                print("datas[] length: "..#data.datas)
                for i = 1, #data.datas, 1 do
                    print("rule title: "..data.datas[i].title)
                end
            end
        end
    end)
end

mytmr = tmr.create()
mytmr:alarm(500, tmr.ALARM_AUTO, function ()
    wifi_ip  = wifi.sta.getip()
    if wifi_ip ~= nil then
        print(wifi_ip)
        mytmr:stop()
        boa_rules()
    end
    print("----getip---")
end)
